package com.eastmoney.emis.edda.infrastructure.report.repository;

import com.eastmoney.emis.edda.infrastructure.report.ReportType;
import com.eastmoney.emis.edda.infrastructure.report.mapper.ReportMapper;
import com.eastmoney.emis.edda.infrastructure.report.po.EmhkHsbcReportFilePo;
import org.aspectj.bridge.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.text.MessageFormat;
import java.time.LocalDateTime;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.infrastructure.report.repository
 * @author: 汪程程
 * @date: 2022/11/3 1:32 PM
 * @version: 1.0
 */
@Repository
public class ReportRepositoryImpl implements ReportRepository {

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public void save(LocalDateTime pullDate, String fileName, String storePath, ReportType type) {
        EmhkHsbcReportFilePo emhkHsbcReportFilePo = new EmhkHsbcReportFilePo();
        emhkHsbcReportFilePo.PULLTIME = pullDate;
        emhkHsbcReportFilePo.REPORTFILENAME = fileName;
        emhkHsbcReportFilePo.TYPE = type.getId();
        emhkHsbcReportFilePo.MINIOFILENAME = storePath;
        reportMapper.addReportFile(emhkHsbcReportFilePo);
    }

    @Override
    public EmhkHsbcReportFilePo findByDateAndType(String reportDate, ReportType type) {
        return reportMapper.findByFileName(type.formatFileName(reportDate));
    }

    @Override
    public boolean exists(String reportDate, ReportType type) {
        return reportMapper.exists(type.formatFileName(reportDate));
    }

}
